/**
 * Class: Sine
 *
 * Purpose: 
 *
 * Created: Jan 30, 2010 @ 10:26:20 AM
 * @author Ken Scott
 */
package org.openfantasia.musica.instruments;

import org.openfantasia.musica.Musica;
import net.beadsproject.beads.core.UGen;
import net.beadsproject.beads.data.Buffer;
import net.beadsproject.beads.events.KillTrigger;
import net.beadsproject.beads.ugens.Envelope;
import net.beadsproject.beads.ugens.Gain;
import net.beadsproject.beads.ugens.WavePlayer;

public class Saw extends Instrument {

	public Saw(Musica musica) {
		super(musica);
	}


	public UGen getSound(double frequency) {
		return new WavePlayer(musica.audioContext, (float) frequency, Buffer.SAW);
	}


	public UGen getEnvelope(double volume, double durationNanos) {
		Gain result = musica.newGain(1, musica.newEnvelope(volume));
		((Envelope) result.getGainEnvelope()).addSegment(0, (float) durationNanos / 1000000f, new KillTrigger(result));
		return result;
	}
}